package com.clarence.dada.modular.system.user.entity.resp;

import cn.hutool.core.bean.BeanUtil;
import com.clarence.dada.core.auth.entity.LoginUser;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/**
 * 登录操作的响应结果
 *
 * @author GD
 * @since 2020/10/19 14:17
 */
@Data
@Schema(title = "登录响应实例")
public class LoginResp {

    /**
     * 登录人的信息
     */
    @Schema(title = "登录人的信息", example = "张三....")
    private LoginUser loginUser;

    /**
     * 登录人的token
     */
    @Schema(title = "登录人的token", example = "token")
    private String token;

    /**
     * 到期时间
     */
    @Schema(title = "到期时间", example = "1735660800000")
    private Long expireAt;


    /**
     * 用于普通登录的组装
     *
     * @author GD
     * @since 2021/5/25 22:31
     */
    public LoginResp(LoginUser loginUser, String token, Long expireAt) {
        this.loginUser = uselessFilter(loginUser);
        this.token = token;
        this.expireAt = expireAt;
    }

    /**
     * 过滤无用的用户信息返回给登录用户
     *
     * @author GD
     * @since 2021/7/13 11:23
     */
    private LoginUser uselessFilter(LoginUser loginUser) {
        LoginUser tempUser = new LoginUser();
        BeanUtil.copyProperties(loginUser, tempUser);

        // 过滤一些内容
        tempUser.setResourceUrls(null);
        tempUser.setToken(null);
        return tempUser;
    }

}
